﻿@using System.Data
@{
    ViewBag.Title = "OrderList";
    Layout = "~/Areas/Mall/Views/Shared/MallLayout1.cshtml";
   DataTable table= ViewData["goodinfo"] as DataTable;
}
<script src="/Scripts/ajaxfileupload.js"></script>
<div class="pjsp">
    <a href="@Url.Action("GoodDetail", "Goods", new { gid = table.Rows[0]["Id"] })">@table.Rows[0]["Name"]</a><br/>
    @{
        for (int i = 1; i <= 3; i++)
        {
            if (table.Rows[0]["Img"+i].ToString().Trim() != "")
            {
                 <img src="@table.Rows[0]["Img" + i].ToString()" />
            }
        }
    }
</div>

<div style="width: 100%;height: 5px;background: red; margin-top: 10px;"></div>
<div style="font-size: 12px;margin-top: 10px;" >
    评价内容
</div>
<div>
    <textarea id="content" style="width: 95%;height: 50px; margin-left: 2%;"></textarea>
</div>

<div style="font-size: 12px;">
    宝贝快照
</div>

<div class="pjimg">
    <img src="/Images/sctp.jpg" onclick="checkfile()"  />
    <input id="fileToUpload" style="display: none; cursor: pointer;" type="file" onchange="upload()" name="upfile">
  
</div>

<div>

</div>
<div style="font-size: 12px;">
    评价星级
</div>
<div class="pjrnk" style="margin-top:10px;">
    <input type="hidden" id="rnk" value="5"/>
    <img src="/Images/redx.png" />
    <img src="/Images/redx.png" />
    <img src="/Images/redx.png" />
    <img src="/Images/redx.png" />
    <img src="/Images/redx.png" />
</div>

<div class ="pjrnk" style="margin-top:20px;">
    <div class="pingjiasave">评价</div>
</div>
<script>
    $(function() {
        
    });
    $(".pingjiasave").click(function () {
        var orderno = "@ViewData["orderno"]";
        var gid = "@ViewData["id"]";
        var content = $("#content").val();
        var rnk = $("#rnk").val();
        var img = "";
        if ($(".pjimg img").size()> 1) {
            $(".pjimg img").each(function(i) {
                if (i >= 1) {
                    img += $(this).attr("src")+",";
                }  
            });
            img = img.substring(0, img.length - 1);
        }
      
        $.post("@Url.Action("EditPingJian")",{id:0,gid:gid,rnk:rnk,img:img,content:content,orderno:orderno},function(row) {
            if (row > 0) {
                alert("感谢您的评价！");
                history.go(-1);
            } else {
                alert("评价失败！");
            }
        });
    });
    

    $(".pjrnk img").click(function() {
        var j = $(this).index();
         $("#rnk").val(j);

        for (var i=0;i<=j;i++) {
            $(".pjrnk img:eq(" + i + ")").attr("src", "/Images/redx.png");
        }
        for (var i = 5; j<=i; i--) {
            $(".pjrnk img:eq(" + i + ")").attr("src", "/Images/blackx.png");
        }
    });

    function checkfile() {
        if ($(".pjimg img").size() == 4) {
            alert("只能上传三张图片！");
            return false;
        }
        $('#fileToUpload').click();
    }
    function upload() {
        var val = $("#fileToUpload").val();
        if (val == "") {
            alert("请上传文件");
            return false;
        }
        var suffix = val.split('.');
        var arr = new Array("png", "jpg", "gif");
        if (arr.indexOf(suffix[suffix.length - 1]) < 0) {
            alert("上传格式有误！");
        } else {
            $.ajaxFileUpload({
                url: '@Url.Action("UploadImg")',
                secureuri: false,
                fileElementId: 'fileToUpload',
                dataType: 'json',
                success: function (data, status) {
                    var str = "";
                    if (data.status == 1) {
                        $(".pjimg").append("<img src=\"" + data.path + "\"/>");
                        
                    } else {

                    }

                }
            });
        }
    }
</script>